package com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.action;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.bo.ITXingzhengshouwenFujianBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.bo.ITXingzhengshouwenNeirongBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.vo.TXingzhengshouwenFujian;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.vo.TXingzhengshouwenNeirong;
import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;

public class WuLiuChengZhuanHuanDengJiFromAction extends Action{
	private ISystemUserBo systemUserBo;
	private ITXingzhengshouwenNeirongBO xingzhengshouwenNeirongBO;
	private ITXingzhengshouwenFujianBO xingzhengshouwenFujianBO;
	public ITXingzhengshouwenNeirongBO getXingzhengshouwenNeirongBO() {
		return xingzhengshouwenNeirongBO;
	}
	public void setXingzhengshouwenNeirongBO(
			ITXingzhengshouwenNeirongBO xingzhengshouwenNeirongBO) {
		this.xingzhengshouwenNeirongBO = xingzhengshouwenNeirongBO;
	}
	public ISystemUserBo getSystemUserBo() {
		return systemUserBo;
	}
	public void setSystemUserBo(ISystemUserBo systemUserBo) {
		this.systemUserBo = systemUserBo;
	}
	
	public ITXingzhengshouwenFujianBO getXingzhengshouwenFujianBO() {
		return xingzhengshouwenFujianBO;
	}
	public void setXingzhengshouwenFujianBO(
			ITXingzhengshouwenFujianBO xingzhengshouwenFujianBO) {
		this.xingzhengshouwenFujianBO = xingzhengshouwenFujianBO;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		String qingban = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengshouwen/properties/systemResource_zh_CN.properties", this).getProperty("xingzhengshouwen.qingban");
		String fileurl = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengshouwen/properties/systemResource_zh_CN.properties", this).getProperty("xingzhengshouwen.fileurl"); 
		List<TSystemUser> systemuserlist = systemUserBo.selectByDutyName(qingban);
		if (systemuserlist != null &&systemuserlist.size() > 0) {
			TSystemUser systemUser = systemuserlist.get(0);
			request.setAttribute("qingbanname", systemUser.getUserName());
			request.setAttribute("qingbanid", systemUser.getUserId());
		
		} else {
			request.setAttribute("qingbanname", "admin");
			request.setAttribute("qingbanid", 1);
		}
		Integer zongshouwenbianhao = xingzhengshouwenNeirongBO.selectMaxZongShouWenHaoByYear();
		if(zongshouwenbianhao==0)
		{
			zongshouwenbianhao=1;
		}
		if(zongshouwenbianhao != 1){
			request.setAttribute("zongshouwenbianhao", (new Date().getYear()+ 1900)+zongshouwenbianhao.toString().substring(4));
		}else{
			request.setAttribute("zongshouwenbianhao", (new Date().getYear()+ 1900)+"0001");
		}
		
		Integer dataBaseId = Integer.parseInt(request.getParameter("dataBaseId"));
		String id = request.getParameter("id");
		TXingzhengshouwenNeirong xingzhengshouwenNeirong =   xingzhengshouwenNeirongBO.selectDownXingzhengshouwenNeirongById(dataBaseId, id);
		List<TXingzhengshouwenFujian> list =  xingzhengshouwenNeirongBO.selectDownXingzhengshouwenFuJian(dataBaseId, id);
		request.setAttribute("xingzhengshouwenNeirong", xingzhengshouwenNeirong);
				
		ToolKit.copyFile(request.getSession().getServletContext().getRealPath("/") + "\\"+ "documentationflow\\xingzhengfawen\\docs\\"+xingzhengshouwenNeirong.getDocId(), fileurl+"\\"+xingzhengshouwenNeirong.getDocId());
		for (TXingzhengshouwenFujian xingzhengshouwenFujian : list) {
			ToolKit.copyFile(request.getSession().getServletContext().getRealPath("/") + "\\"+ "documentationflow\\xingzhengfawen\\docs\\"+xingzhengshouwenFujian.getFujianZhengname(), fileurl+"\\"+xingzhengshouwenFujian.getFujianZhengname());
			xingzhengshouwenFujian.setFujianAddress("D:\\gongwen\\xingzhengshouwen\\"+xingzhengshouwenFujian.getFujianZhengname());
			TXingzhengshouwenNeirong neirong = new TXingzhengshouwenNeirong();
			neirong.setId("0");
			xingzhengshouwenFujian.setXingzhengshouwenNeirong(neirong);
			String fujianid =  xingzhengshouwenFujianBO.addFujianId(xingzhengshouwenFujian);
			xingzhengshouwenFujian.setId(fujianid);
		}
		TXingzhengshouwenFujian xingzhengshouwenFujian = new TXingzhengshouwenFujian();
		xingzhengshouwenFujian.setFujianName(xingzhengshouwenNeirong.getZhaiyou());
		xingzhengshouwenFujian.setFujianZhengname(xingzhengshouwenNeirong.getDocId());
		xingzhengshouwenFujian.setFujianAddress("D:\\gongwen\\xingzhengshouwen\\"+xingzhengshouwenFujian.getFujianZhengname());
		TXingzhengshouwenNeirong neirong = new TXingzhengshouwenNeirong();
		neirong.setId("0");
		xingzhengshouwenFujian.setXingzhengshouwenNeirong(neirong);
		String fujianid =  xingzhengshouwenFujianBO.addFujianId(xingzhengshouwenFujian);
		xingzhengshouwenFujian.setId(fujianid);		
		list.add(0, xingzhengshouwenFujian);
		request.getSession().setAttribute("xingzhengshouwenNeirongFuJianList", list);
		String taskId = request.getParameter("taskId");
		request.setAttribute("taskId", taskId);
		request.setAttribute("dataBaseId", dataBaseId);		
		return mapping.findForward("ok");
	}
	
}


